package daybook.model.transaction;

import daybook.annotation.Bean;
import daybook.model.Account;
import org.immutables.value.Value;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Set;

@Bean
@Value.Immutable
public abstract class LedgerEntry {
    @Value.Parameter
    public abstract Transaction getTransaction();
    @Value.Parameter
    public abstract TransactionEntry getTransactionEntry();

    @Value.Default
    @Value.Parameter
    public BigDecimal getBalance() {
        return BigDecimal.ZERO;
    }

    public static LedgerEntry of(Transaction transaction, TransactionEntry transactionEntry, BigDecimal balance) {
        return ImmutableLedgerEntry.of(transaction, transactionEntry, balance.add(transactionEntry.getAmount()));
    }

    public LocalDate getDate() {
        return getTransaction().getDate();
    }

    public boolean isChecked() {
        return getTransaction().isChecked();
    }

    public int getDc() {
        return getTransactionEntry().getDc();
    }

    public Account getAccount() {
        return getTransactionEntry().getAccount();
    }

    public BigDecimal getAmount() {
        return getTransactionEntry().getAmount();
    }

    public String getDescription() {
        return getTransaction().getDescription();
    }

    public Set<Item> getItems() {
        return getTransactionEntry().getItems();
    }
}
